﻿using BCVP.Net8.IService;
using BCVP.Net8.Model.Models;
using BCVP.Net8.Model.ViwModels;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;

using Newtonsoft.Json;

namespace BCVP.Net8.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class BookController : ControllerBase
    {
        private readonly IBookService _bookService;
        public BookController(IBookService bookService)
        {
            _bookService = bookService;
        }

        [HttpGet("QueryBooks")]
        public async Task<object> QueryBookList()
        {
            var list = await _bookService.QueryAll();
            return list;
        }

        [HttpPost("Add")]
        public async Task<object> AddBook([FromBody] BookViewModel bookView)
        {
            var model = await _bookService.Add(bookView);
            return JsonConvert.SerializeObject(model);
        }

    }
}
